﻿@using Smartstore.Core.Common;
@using Smartstore.Core.Catalog.Pricing;
@using Smartstore.Web.Models.Catalog;

@model ProductSummaryItemModel

@{
    var list = Model.Parent;
    if (!list.ShowPrice || Model.Price == null)
    {
        return;
    }

    var price = Model.Price;
    var isLinesMode = list.ViewMode == ProductSummaryViewMode.List;
    var showPriceSaving = isLinesMode && price.Saving.SavingAmount.HasValue && (price.ShowRetailPriceSaving || price.RegularPrice != null);
    var artPriceClass = "art-price";

    if (price.Saving.HasSaving)
    {
        artPriceClass += " art-price-offer";
    }

    if (price.CallForPrice)
    {
        artPriceClass += " art-price-call";
    }

    async Task RenderComparePrice(ComparePriceModel priceModel)
    {
        <span sm-if="priceModel != null" class="art-compareprice">
            @if (isLinesMode || price.ShowPriceLabel)
            {
                <span class="art-compareprice-label">@(priceModel.Label):</span>
            }
            <data asp-for="@priceModel.Price" class="art-compareprice-value">@priceModel.Price</data>
        </span>
    }
}

<div class="art-price-block">
    <span class="@artPriceClass">
        <span class="art-finalprice">
            @if (price.HasCalculation)
            {
                <data asp-for="@price.FinalPrice" class="art-price-value">
                    @Html.Raw(price.FinalPrice)
                </data>
            }
        </span>

        @* Compare prices *@
        <span sm-if="price.RegularPrice != null || price.RetailPrice != null" class="art-info-group">
            @{ 
                // Regular price
                await RenderComparePrice(price.RegularPrice);

                // Retail price
                if (isLinesMode || price.RegularPrice == null)
                {
                    // Don't render retail price in compact mode if we have a regular price already
                    await RenderComparePrice(price.RetailPrice);
                }
            }

            @* You save *@
            <span sm-if="showPriceSaving" class="art-compareprice">
                <span class="art-compareprice-label">@T("ShoppingCart.ItemYouSave"):</span>
                <data asp-for="@price.Saving.SavingAmount" class="art-saving">@price.Saving.SavingAmount.Value</data>
            </span>
        </span>
    </span>

    <div sm-if="list.ShowShippingSurcharge && price.ShippingSurcharge.HasValue" class="art-shipsurcharge">
        <data asp-for="@price.ShippingSurcharge">@price.ShippingSurcharge.Value</data>
    </div>
    <div sm-if="list.ShowBasePrice && price.BasePriceInfo.HasValue()" class="art-pangv" title="@price.BasePriceInfo">
        @Html.Raw(LocalizedValue.FixBrackets(price.BasePriceInfo, WorkContext.WorkingLanguage) ?? "&nbsp;")
    </div>
</div>

<zone name="productbox_add_info" />